<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }">
        <TableAction
          v-if="record.status === 3"
          :actions="[
            {
              label: '审核',
              onClick: handleApprove.bind(null, record),
            },
          ]"
        />
      </template>
    </BasicTable>
    <RefundModal @register="registerModal" @success="handleSuccess" />
  </div>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';

  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { getRefundOrderList } from '/@/api/sys/refundOrder';

  import RefundModal from './refundModal.vue';
  import { useModal } from '/@/components/Modal';

  import { columns, searchFormSchema } from './refundData';

  export default defineComponent({
    name: 'RefundList',
    components: { BasicTable, RefundModal, TableAction },
    setup() {
      const [registerModal, { openModal: openModal }] = useModal();

      const [registerTable, { reload }] = useTable({
        title: '退款订单列表',
        api: getRefundOrderList,
        // dataSource: [{ orderId: 'a1111' }],
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        showIndexColumn: false,
        actionColumn: {
          width: 80,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: undefined,
        },
        fetchSetting: {
          pageField: 'pageNum',
          totalField: 'totalCount',
          listField: 'list',
          sizeField: 'pageSize',
        },
      });

      function handleApprove(record: Recordable) {
        console.log(record);

        openModal(true, {
          order: record,
          isUpdate: true,
        });
      }

      function handleSuccess() {
        reload();
      }

      return {
        registerTable,
        registerModal,
        openModal,
        handleApprove,
        handleSuccess,
      };
    },
  });
</script>
